﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CategoryProp>" %>
<%@ Import Namespace="LuKou.Web.BLL.Service" %>
<%
    Goods goods = (Goods)ViewData["Goods"];
    List<long> values = new List<long>();
    List<String> defValur = new List<string>();
    if (goods != null)
    {
        values = goods.Attribs.FindAll(c => c.Pid == Model.Pid).Select(c => c.Vid).ToList();
        defValur = goods.DefAttribs.FindAll(c => c.Pid == Model.Pid).Select(c => c.CharValue).ToList();
    }
%>

<%=Html.Hidden("TbAttr.index",Model.ID) %>
<div class="prop_name">
    <label><%=Model.Must ? "<span>*</span>" : ""%><%=Model.Name%>：</label>
    <%=Html.Hidden(string.Format("TbAttr[{0}].Pid",Model.ID), Model.Pid)%>
</div>

<div class="prop_value">
<%if (Model.IsEnumProp){
    List<CategoryPropValue> options = CategoryService.GetCategoryPropValueList(Model.CategoryID, Model.Pid);

    //不能多选，下拉
    if (!Model.Multi){
        //组合数据
        List<SelectListItem> select = new List<SelectListItem>();
        select.Add(new SelectListItem(){Text = "--请选择--", Value = "-1"});
        if (Model.IsInputProp)
        {
            select.Add(new SelectListItem() {Text = "--自定义--", Value = "-2", Selected = defValur.Count > 0});
        }
        select.AddRange(options.Select(op => new SelectListItem() {Text = op.Name, Value = op.Vid.ToString(), Selected = values.Contains(op.Vid)}));
%>
        <%=Html.DropDownList(string.Format("TbAttr[{0}].Vid", Model.ID), select)%>
        <%if (Model.IsInputProp && defValur.Count > 0){%>
            <%=Html.TextBox(string.Format("TbAttr[{0}].Vid", Model.ID), defValur.FirstOrDefault())%>
        <%}%>
    <%}else{%>
        <%
        foreach (var option in options){
            Dictionary<string, object> htmlOptins = new Dictionary<string, object>();
            htmlOptins["type"] = "checkbox";
            if (values.Contains(option.Vid)){
                htmlOptins["checked"] = "checked";
            }
        %>
        <label>
            <%=Html.TextBox(string.Format("TbAttr[{0}].Vid", Model.ID), option.Vid, htmlOptins)%>
            <%=option.Name%>
        </label>
        <%}%>
    <%}%>
<%}else{%>
<%=Html.TextBox(string.Format("TbAttr[{0}].Vid", Model.ID), defValur.FirstOrDefault())%>
<%}%>
</div>